package com.cskaoyan.gateway.controller.shopping;

import com.cskaoyan.gateway.form.shopping.RealGoodsResponse;
import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.TbItemGoodService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.QueryGoodListRequest;
import com.mall.shopping.dto.QueryGoodListResponse;
import com.mall.user.annotation.Anoymous;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: lin
 * @Date: 2020/7/10 9:09
 */

@RestController
@RequestMapping("shopping")
@Anoymous
public class ShoppingGoodsController {

    @Reference(check = false)
    TbItemGoodService itemGoodService;

    @GetMapping("goods")
    @Anoymous
    public ResponseData GoodsHandler(QueryGoodListRequest request){
        QueryGoodListResponse response = itemGoodService.getGoods(request);
        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            RealGoodsResponse realGoodsResponse = new RealGoodsResponse(
                    response.getData(),
                    response.getTotal()
            );
            return new ResponseUtil().setData(realGoodsResponse);
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }
}
